/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 苏李涛
 * Date: 2024-05-30
 * Time: 20:29
 */
public class Test {

    public static void main(String[] args) {
        StringBuilder stringBuilder = new StringBuilder("haha");
        System.out.println(stringBuilder.insert(2, "xixi"));
    }
    public static void main1(String[] args) {

        String s1 = "这样";
        s1 += "拼接";


        //1.即尾插-->字符、字符串、整形数字,相当于上面的拼接
        StringBuilder stringBuilder = new StringBuilder("haha");
        System.out.println(stringBuilder.append(1));


        //要接受，就用toString转化为String类型
        String ret = stringBuilder.toString();
        System.out.println(ret);
    }

    public static void main2(String[] args) {
        long start = System.currentTimeMillis();
        String s = "";
        for(int i = 0; i < 10000; ++i){
            s += i;
        }
        long end = System.currentTimeMillis();
        System.out.println(end - start);

        start = System.currentTimeMillis();
        StringBuffer sbf = new StringBuffer("");
        for(int i = 0; i < 10000; ++i){
            sbf.append(i);
        }
        end = System.currentTimeMillis();
        System.out.println(end - start);
        start = System.currentTimeMillis();

        StringBuilder sbd = new StringBuilder();
        for(int i = 0; i < 10000; ++i){
            sbd.append(i);
        }
        end = System.currentTimeMillis();
        System.out.println(end - start);
    }

}
